<!DOCTYPE html>
<html lang="en">
<title>门店列表</title>
<#import "/layout/layout.html" as body/>
<@body.page>

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12 margin-top">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5 class="pull-left">店铺列表</h5>
                    <!--<button type="button" class="btn btn-primary btn-sm pull-right">导出表格</button>-->
                </div>
                <div class="ibox-content">
                    <div class="table-responsive">
                        <form class="form-inline" role="form">
                            <div class="form-group">
                                <label for="storeName">门店名：</label>
                                <input class="form-control" type="text" id="storeName" name="storeName"/>
                            </div>
                            <div class="form-group margin-left">
                                <div class="input-group">
                                    <!--<div class="input-group-addon">地址：</div>-->
                                    <label fclass="sr-only">地址：</label>
                                    <div id="citys" class="citys" style="display: inline-flex;">
                                        <select class="form-control" id="province" name="province"></select>
                                        <select class="form-control" id="city" name="city"></select>
                                        <select class="form-control" id="area" name="area"></select>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group margin-left">
                                <label class="sr-only">状态：</label>
                                状态：
                                <select class="form-control" id="status" name="status">
                                    <option value="">全部</option>
                                    <option value="1">即将开业</option>
                                    <option value="2">运营中</option>
                                    <option value="3">已停业</option>
                                </select>
                            </div>
                            <button type="button" onclick="storePage(1)" class="btn btn-outline btn-primary" style="margin-top: 5px">确认</button>
                        </form>
                        <hr style="width: 100%">
                        <table class="table table-hover table-center dataTables-example">
                            <thead>
                            <tr>
                                <th>门店ID</th>
                                <th>门店名称</th>
                                <th>地址</th>
                                <th>门店房租</th>
                                <th>店长</th>
                                <th>自健</th>
                                <th>自健价格</th>
                                <th>会员价格</th>
                                <th>类型</th>
                                <th>经营</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody id="courseList">
                            </tbody>
                        </table>
                    </div>

                </div>
                <div class="ibox-footer overflow">
                    <h4 class="pull-left">合计：<span id="storeCount">0</span>家门店</h4>
                    <div id="copot-page" class="pull-right"></div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    //        $('#demo').citys({nodata: 'hidden', code: ${area!440300}});
    $('#citys').citys({
        required: false,
        nodata: 'disabled'
    });
    $(document).ready(function () {
        //导出excel
//            ExampleFile('门店列表');

        storePage(1);
    });

    //分页方法
    function storePage(currentIndex) {
//        debugger
        var param = {
            "pageIndex": currentIndex,
            "pageSize": 10,
            "storeName": $("#storeName").val(),
            "province": $("#province option:selected").text().replace("省份", "").trim(),
            "city": $("#city option:selected").text().replace("城市", "").trim(),
            "area": $("#area option:selected").text().replace("区域", "").trim(),
            "status": $("#status").val()
        };
        $("#courseList").empty();
        $.ajax({
            url: "${baseUrl}system/store/store_list",
            data: param,
            type: "POST",
            success: function (result) {
                var html = "";
                //分页
                new Page({
                    parent: $("#copot-page"),
                    nowPage: currentIndex,
                    pageSize: 10,
                    totalCount: result.storeCount,
                    setting: {
                        defaultPage: 5,//默认显示可点击分页的个数
                        firstPageText: "首页",
                        prevPageText: "上一页",
                        nextPageText: "下一页",
                        lastPageText: "尾页"
                    },
                    callback: function (nowPage, totalPage) {
                        storePage(nowPage);
                    }
                });

                $("#storeCount").text(result.storeCount);
                var storeRent = null;
                var nickName = null;
                var isSelfWorkOutSup = false;
                
                var primePrice = null;
                var price = null;
                var status = null;
                var manageType = null;
                var storeType = null;
                $.each(result.storeList, function (i, data) {
                	var maxCount = 0;
                    if (data.storeRent) {
                        storeRent = "¥" + data.storeRent;
                    } else {
                        storeRent = "无";
                    }
                    if (data.nickName) {
                        nickName = data.nickName;
                    } else {
                        nickName = "无";
                    }
                    if (data.isSelfFitness) {
                        if (data.isSelfFitness == 1) {
                            isSelfWorkOutSup = "团课及自助";
                        }else if(data.isSelfFitness == 2){
                        	isSelfWorkOutSup = "仅支持自助";
                        }else if(data.isSelfFitness == 3){
                            isSelfWorkOutSup = "仅支持私教";
                        } else {
                            isSelfWorkOutSup = "仅支持团课";
                            primePrice = "不支持";
                            price = "不支持";
                        }
                    }
                    if (data.maxCount > 0) {
                        maxCount = data.maxCount;
                    }
                    if(data.primePrice>=0){
                        primePrice = data.primePrice;
                    }
                    if(data.price>=0){
                        price = data.price;
                    }

                    if (data.status) {
                        if (data.status == 1) {
                            status = "即将开业";
                        }
                        if (data.status == 2) {
                            status = "运营中";
                        }
                        if (data.status == 3) {
                            status = "休息中";
                        }
                        if (data.status == 4) {
                            status = "已停业";
                        }
                        if (data.status == 5) {
                            status = "已删除";
                        }
                    }
                    if (data.manageType) {
                        if (data.manageType == 1) {
                            manageType = "自营";
                        } else if (data.manageType == 2) {
                            manageType = "加盟";
                        }
                    }
                    if (data.storeType) {
                        if (data.storeType == 1) {
                            storeType = "CBD店";
                        } else if (data.storeType == 2) {
                            storeType = "社区店";
                        }
                    }
                    html += "<tr><td>" + data.id + "</td>";
                    html += "<td>" + data.storeName + "</td>";
                    html += "<td>" + data.province + "/" + data.city + "/" + data.area + "<br />" + data.address + "</td>";
                    html += "<td>" + storeRent + "</td>";
                    html += "<td>" + nickName + "</td>";
                    if(data.isSelfFitness == 1){
                        html += "<td>" + isSelfWorkOutSup + "(" + maxCount + ")  </td>";
                    } else {
                        html += "<td>" + isSelfWorkOutSup + "</td>";
                    }
                    html += "<td>" + primePrice + "</td>";
                    html += "<td>" + price + "</td>";
                    html += "<td>" + manageType + "</td>";
                    html += "<td>" + storeType + "</td>";
                    html += "<td>" + status + "</td>";
                    html += "<td>";
//                        html += "<button type='button' onclick='detailStore("+data.id+")' class='btn btn-default'><i class='fa fa-eye'></i> 查看</button>";
                    html += "<button type='button' onclick='editStore(" + data.id + ")' class='btn btn-default'><i class='fa fa-pencil'></i> 编辑</button>";
                    if (data.status == 1 ) {
                        html += "<button type='button' onclick='openStore(" + data.id + ")' class='btn btn-default'><i class='fa fa-arrow-circle-o-up'></i> 开业</button>";
                        html += "<button type='button' onclick='closeStore(" + data.id + ")' class='btn btn-default'><i class='fa fa-ban'></i> 停业</button>";

                    }
                    if (data.status == 2) {
                        html += "<button type='button' onclick='closeStore(" + data.id + ")' class='btn btn-default'><i class='fa fa-ban'></i> 停业</button>";
                        html += "<button type='button' onclick='readyStore(" + data.id + ")' class='btn btn-default'><i class='fa fa-arrow-circle-o-up'></i> 即将开业</button>";

                    }
                    if (data.status == 4){
                        html += "<button type='button' onclick='openStore(" + data.id + ")' class='btn btn-default'><i class='fa fa-arrow-circle-o-up'></i> 开业</button>";
                        html += "<button type='button' onclick='readyStore(" + data.id + ")' class='btn btn-default'><i class='fa fa-arrow-circle-o-up'></i> 即将开业</button>";
                    }
//                        html += "<button type='button' onclick='deleteStore("+data.id+")' class='btn btn-default'><i class='fa fa-trash-o'></i>删除(测试)</button>";
                    html += "</td>";
                    html += "</tr>";
                });
                $("#courseList").html(html);
            }
        });
    }

    //查看
    function detailStore(id) {
        window.location = "to_store_detail?id=" + id;
    }

    //跳转编辑
    function editStore(id) {
        window.location = "to_store_edit?id=" + id;
    }

    //即将开业
    function readyStore(storeId) {

        swal({
            title: "确定要即将开业吗?",
            text: "点击后门店立即变为即将开业状态!",
            type: "question",
            showCancelButton: true,
            cancelButtonColor: '#d33',
            cancelButtonText: "容我三思！",
            confirmButtonText: "即将开业!"
        }).then(function () {
            $.ajax({
                type: "post",
                url: "store_ready",
                data: {"id": storeId},
                success: function (result) {
                    if (result) {
                        swal("即将开业成功!", "页面即将重新加载,请稍后...", "success");
                        window.setTimeout(function () {
                            window.location.reload()
                        }, 1000);
                    }
                }
            });
        }, function () {
        });
    }

    //开业
    function openStore(storeId) {

        swal({
            title: "确定要开业吗?",
            text: "点击后门店立即变为开业状态!",
            type: "question",
            showCancelButton: true,
            cancelButtonColor: '#d33',
            cancelButtonText: "容我三思！",
            confirmButtonText: "开业!"
        }).then(function () {
            $.ajax({
                type: "post",
                url: "store_open",
                data: {"id": storeId},
                success: function (result) {
                    if (result) {
                        swal("开业成功!", "页面即将重新加载,请稍后...", "success");
                        window.setTimeout(function () {
                            window.location.reload()
                        }, 1000);
                    }
                }
            });
        }, function () {
        });
    }

    //停业
    function closeStore(storeId) {

        swal({
            title: "确定要停业吗?",
            text: "点击后门店立即变为停业状态!",
            type: "question",
            showCancelButton: true,
            cancelButtonColor: '#d33',
            cancelButtonText: "容我三思！",
            confirmButtonText: "停业!"
        }).then(function () {
            $.ajax({
                type: "post",
                url: "store_close",
                data: {"id": storeId},
                success: function (result) {
                    if (result) {
                        swal("停业成功!", "页面即将重新加载,请稍后...", "success");
                        window.setTimeout(function () {
                            window.location.reload()
                        }, 1000);
                    }
                }
            });
        },function () {
        });
    }
    //      删除
    //        function deleteStore(storeId){
    //
    //            swal({
    //                title: "确定删除吗?",
    //                text: "删除后不可恢复!",
    //                type: "warning",
    //                showCancelButton: true,
    //                confirmButtonColor: "#DD6B55",
    //                cancelButtonText: "容我三思！",
    //                confirmButtonText: "删除!",
    //                closeOnConfirm: false
    //            }, function(){
    //                $.ajax({
    //                    type:"post",
    //                    url:"store_delete",
    //                    data:{"id":storeId},
    //                    success: function (result) {
    //                        if(result){
    //                            swal("删除成功!", "页面即将重新加载,请稍后...", "success");
    //                            window.setTimeout(function(){window.location.reload()},1000);
    //                        }
    //                    }
    //                });
    //            });
    //        }
</script>

</@body.page>
</html>